//
//  SecondViewController.m
//  07-Delegate和Block
//
//  Created by 曹曹 on 16/7/22.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "SecondViewController.h"

@interface SecondViewController ()
@property (nonatomic, strong) UITextField *textField;
@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 创建一个textField
    self.textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];
    _textField.placeholder = @"textField";
    _textField.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:_textField];
    //
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor redColor];
    [button setTitle:@"上一页" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.frame = CGRectMake(150, 200, 100, 50);
    [button addTarget:self action:@selector(handleButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    // 接收第一页传过来的值
    _textField.text = _secondTitle;
}

- (void)handleButton:(UIButton *)button {
    // 属性往前传值
//    NSInteger count = self.navigationController.viewControllers.count;
#warning find previous object
//    ViewController *firstVC = self.navigationController.viewControllers[count - 2];
//    firstVC.titleTextField = _textField.text;
#warning 触发协议方法(Judge Delegate存不存在, 判断代理人有没有实现协议方法)
    if (self.delegate && [self.delegate respondsToSelector:@selector(passValue:)]) {
        [self.delegate passValue:_textField.text];
    }
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
